package com.central.monitor.redis

import java.lang

import com.alibaba.fastjson.JSON
import com.central.utils.ConfigUtil
import com.redislabs.provider.redis._
import org.apache.spark.{SparkConf, SparkContext}
import redis.clients.jedis.{JedisPool, JedisPoolConfig, Protocol}

import scala.util.parsing.json.JSONObject

object MonitorRedisMethod {

  val host: String = ConfigUtil.properties.getProperty("redis.host")
  val password: String = ConfigUtil.properties.getProperty("redis.password")
  val port: Integer = ConfigUtil.properties.getProperty("redis.port").toInt

  private val jedisPoolConfig = new JedisPoolConfig
  jedisPoolConfig.setMaxTotal(1000)
  private val jedisPool = new JedisPool(jedisPoolConfig, host, port, 3000, password, 5)

  val NUM_LIST_LENGTH = ConfigUtil.properties.getProperty("redis.num.warning.listlenth").toInt


  def loadNumFromRedis(key: String) = {
    val jedis = jedisPool.getResource
//    val key = "monitor:person:target:4"
    jedis
    val strings = jedis.lrange(key, 0, NUM_LIST_LENGTH)
    jedis.close()
    strings.toArray().map(x => {
      x.asInstanceOf[String]
    })
  }

  def main(args: Array[String]): Unit = {

  }
}
